﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Controller;
using Interfaces;
using System.IO;

namespace GUI
{
    public partial class frmHovedform : Form
    {
        public frmHovedform()
        {
            InitializeComponent();
        }

        private void picSeOpgaver_Click(object sender, EventArgs e)
        {
            frmSeOpgaver seOpgaver = new frmSeOpgaver();
            seOpgaver.ShowDialog();
        }

        private void picOpretOrdre_Click(object sender, EventArgs e)
        {
            frmOpretOrdre opretOrdre = new frmOpretOrdre();
            opretOrdre.ShowDialog();
        }

        private void picUdskrivRegning_Click(object sender, EventArgs e)
        {
            frmUdskrivRegning udskrivRegning = new frmUdskrivRegning();
            udskrivRegning.ShowDialog();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            frmAflevereScooter afsco = new frmAflevereScooter();
            afsco.ShowDialog();
        }

        private void picOpretKunde_Click(object sender, EventArgs e)
        {
            frmOpretKunde frmopretkunde = new frmOpretKunde();
            frmopretkunde.ShowDialog();
        }


        private void picVinterservice_Click(object sender, EventArgs e)
        {
            KundeController kc = new KundeController();
            List<Ikunde> kundeListe = kc.HentKunderDerIkkeHarHarHaftOrdreIAntalDage(365);

            Stream myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Title = "Gem Vinterservice Liste";
            saveFileDialog1.Filter = "Tekst-fil (*.txt)|*.txt";
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    StreamWriter vinterServiceListe = new StreamWriter(myStream);

                    foreach (Ikunde kunde in kundeListe)
                    {
                        vinterServiceListe.WriteLine(kunde.Kundenr + "," + kunde.Navn + "," + kunde.Adresse + "," + kunde.Postnummer + "," + kc.HentByForPostnr(kunde.Postnummer) + "," + kunde.Maerke);
                    }
                    vinterServiceListe.WriteLine("\n");
                    vinterServiceListe.Close();
                    myStream.Close();
                }
            }

        }



        private void picFaerdigmeldOrdre_Click(object sender, EventArgs e)
        {
            frmFaerdigmeldScooter faerdigmedScooter = new frmFaerdigmeldScooter();
            faerdigmedScooter.ShowDialog();
        }

        private void picOpgaver_Click(object sender, EventArgs e)
        {
            frmSeOpgaver seOpgaver = new frmSeOpgaver();
            seOpgaver.ShowDialog();
        }

        private void picUdlejScooter_Click(object sender, EventArgs e)
        {
            frmUdlejScooter udlejScooter = new frmUdlejScooter();
            udlejScooter.ShowDialog();
        }

        private void pictModtagUdlejetScooterRetur_Click(object sender, EventArgs e)
        {
            frmAflevereScooter frmafl = new frmAflevereScooter();
            frmafl.ShowDialog();
            frmAflevereScooter afleverScooter = new frmAflevereScooter();
         afleverScooter.ShowDialog();
        }

        private void btnOpretVare_Click_1(object sender, EventArgs e)
        {
            frmOpretVare opretVare = new frmOpretVare();
            opretVare.ShowDialog();
        }
    }
}
